package com.gaj.controller;

import com.gaj.util.FtpUtils;
import com.gaj.util.ReadXml;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.crypto.Data;
import java.io.File;

@RestController
public class ArticleController {

    @Autowired
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
    private static String xmlPath = "D:\\idea_projects\\gajSpringBoot\\doc\\BJCM政法智能办案平台中心平台项目技术接口标准V4.5.4.2\\标准XML文件下发版\\11_一审公诉_bjcm\\1301E-【法院】结案【检察院、公安、看守所、司法局、监狱】-YWXX.xml";

    //@PostConstruct
    //public void init(){
    //    System.out.println("线程数=" + threadPoolTaskExecutor.getPoolSize());
    //    System.out.println("核心线程数=" + threadPoolTaskExecutor.getCorePoolSize());
    //    System.out.println("活跃线程数=" + threadPoolTaskExecutor.getActiveCount());
    //    System.out.println("空闲时间=" + threadPoolTaskExecutor.getKeepAliveSeconds());
    //    System.out.println("最大线程数=" + threadPoolTaskExecutor.getMaxPoolSize());
    //
    //}

    ////每10秒执行一次
    //@Scheduled(fixedRate = 1000000)
    //@Async
    //public void test1() {
    //    int count = 0;
    //    System.out.println("定时任务1");
    //    while (true) {
    //        try {
    //            System.out.println("当前线程1=" + Thread.currentThread().getName() + " 次数 " + ++count);
    //            Thread.sleep(5000);
    //        } catch (InterruptedException e) {
    //            throw new RuntimeException(e);
    //        }
    //    }
    //}
    //

    /// /每10秒执行一次
    //@Scheduled(fixedRate = 1000000)
    //@Async
    //public void test2() {
    //    int count = 0;
    //    System.out.println("定时任务2......");
    //    while (true) {
    //        try {
    //            System.out.println("当前线程2=" + Thread.currentThread().getName() + " 次数 " + ++count);
    //            Thread.sleep(5000);
    //        } catch (InterruptedException e) {
    //            throw new RuntimeException(e);
    //        }
    //    }
    //}
    @Scheduled(initialDelay = 1000, fixedRate = Long.MAX_VALUE) // 容器启动后1秒执行一次，不重复执行
    public void test() {
        FtpUtils.main(new String[]{});

        //ReadXml.batchExecute(1);
        //ReadXml.execute(new File(xmlPath));
    }
}
